package com.iflytek.cloud.desktop.mapper;

import static com.iflytek.cloud.desktop.mapper.ImageInfoDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.iflytek.cloud.desktop.dto.ImageInfo;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface ImageInfoMapper {

    BasicColumn[] selectList = BasicColumn.columnList(id, name, imageId, status, type, volume, osName, creator, appNum, minRam, description, createdTime);


    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);


    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);


    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<ImageInfo> insertStatement);


    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<ImageInfo> multipleInsertStatement);


    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("ImageInfoResult")
    Optional<ImageInfo> selectOne(SelectStatementProvider selectStatement);


    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="ImageInfoResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="image_id", property="imageId", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.BIT),
        @Result(column="volume", property="volume", jdbcType=JdbcType.INTEGER),
        @Result(column="os_name", property="osName", jdbcType=JdbcType.VARCHAR),
        @Result(column="creator", property="creator", jdbcType=JdbcType.VARCHAR),
        @Result(column="app_num", property="appNum", jdbcType=JdbcType.INTEGER),
        @Result(column="min_ram", property="minRam", jdbcType=JdbcType.INTEGER),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="created_time", property="createdTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<ImageInfo> selectMany(SelectStatementProvider selectStatement);


    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);


    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, imageInfo, completer);
    }


    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, imageInfo, completer);
    }


    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }


    default int insert(ImageInfo record) {
        return MyBatis3Utils.insert(this::insert, record, imageInfo, c ->
            c.map(id).toProperty("id")
            .map(name).toProperty("name")
            .map(imageId).toProperty("imageId")
            .map(status).toProperty("status")
            .map(type).toProperty("type")
            .map(volume).toProperty("volume")
            .map(osName).toProperty("osName")
            .map(creator).toProperty("creator")
            .map(appNum).toProperty("appNum")
            .map(minRam).toProperty("minRam")
            .map(description).toProperty("description")
            .map(createdTime).toProperty("createdTime")
        );
    }


    default int insertMultiple(Collection<ImageInfo> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, imageInfo, c ->
            c.map(id).toProperty("id")
            .map(name).toProperty("name")
            .map(imageId).toProperty("imageId")
            .map(status).toProperty("status")
            .map(type).toProperty("type")
            .map(volume).toProperty("volume")
            .map(osName).toProperty("osName")
            .map(creator).toProperty("creator")
            .map(appNum).toProperty("appNum")
            .map(minRam).toProperty("minRam")
            .map(description).toProperty("description")
            .map(createdTime).toProperty("createdTime")
        );
    }


    default int insertSelective(ImageInfo record) {
        return MyBatis3Utils.insert(this::insert, record, imageInfo, c ->
            c.map(id).toPropertyWhenPresent("id", record::getId)
            .map(name).toPropertyWhenPresent("name", record::getName)
            .map(imageId).toPropertyWhenPresent("imageId", record::getImageId)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
            .map(type).toPropertyWhenPresent("type", record::getType)
            .map(volume).toPropertyWhenPresent("volume", record::getVolume)
            .map(osName).toPropertyWhenPresent("osName", record::getOsName)
            .map(creator).toPropertyWhenPresent("creator", record::getCreator)
            .map(appNum).toPropertyWhenPresent("appNum", record::getAppNum)
            .map(minRam).toPropertyWhenPresent("minRam", record::getMinRam)
            .map(description).toPropertyWhenPresent("description", record::getDescription)
            .map(createdTime).toPropertyWhenPresent("createdTime", record::getCreatedTime)
        );
    }


    default Optional<ImageInfo> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, imageInfo, completer);
    }


    default List<ImageInfo> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, imageInfo, completer);
    }


    default List<ImageInfo> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, imageInfo, completer);
    }


    default Optional<ImageInfo> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }


    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, imageInfo, completer);
    }


    static UpdateDSL<UpdateModel> updateAllColumns(ImageInfo record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalTo(record::getId)
                .set(name).equalTo(record::getName)
                .set(imageId).equalTo(record::getImageId)
                .set(status).equalTo(record::getStatus)
                .set(type).equalTo(record::getType)
                .set(volume).equalTo(record::getVolume)
                .set(osName).equalTo(record::getOsName)
                .set(creator).equalTo(record::getCreator)
                .set(appNum).equalTo(record::getAppNum)
                .set(minRam).equalTo(record::getMinRam)
                .set(description).equalTo(record::getDescription)
                .set(createdTime).equalTo(record::getCreatedTime);
    }


    static UpdateDSL<UpdateModel> updateSelectiveColumns(ImageInfo record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalToWhenPresent(record::getId)
                .set(name).equalToWhenPresent(record::getName)
                .set(imageId).equalToWhenPresent(record::getImageId)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(type).equalToWhenPresent(record::getType)
                .set(volume).equalToWhenPresent(record::getVolume)
                .set(osName).equalToWhenPresent(record::getOsName)
                .set(creator).equalToWhenPresent(record::getCreator)
                .set(appNum).equalToWhenPresent(record::getAppNum)
                .set(minRam).equalToWhenPresent(record::getMinRam)
                .set(description).equalToWhenPresent(record::getDescription)
                .set(createdTime).equalToWhenPresent(record::getCreatedTime);
    }


    default int updateByPrimaryKey(ImageInfo record) {
        return update(c ->
            c.set(name).equalTo(record::getName)
            .set(imageId).equalTo(record::getImageId)
            .set(status).equalTo(record::getStatus)
            .set(type).equalTo(record::getType)
            .set(volume).equalTo(record::getVolume)
            .set(osName).equalTo(record::getOsName)
            .set(creator).equalTo(record::getCreator)
            .set(appNum).equalTo(record::getAppNum)
            .set(minRam).equalTo(record::getMinRam)
            .set(description).equalTo(record::getDescription)
            .set(createdTime).equalTo(record::getCreatedTime)
            .where(id, isEqualTo(record::getId))
        );
    }


    default int updateByPrimaryKeySelective(ImageInfo record) {
        return update(c ->
            c.set(name).equalToWhenPresent(record::getName)
            .set(imageId).equalToWhenPresent(record::getImageId)
            .set(status).equalToWhenPresent(record::getStatus)
            .set(type).equalToWhenPresent(record::getType)
            .set(volume).equalToWhenPresent(record::getVolume)
            .set(osName).equalToWhenPresent(record::getOsName)
            .set(creator).equalToWhenPresent(record::getCreator)
            .set(appNum).equalToWhenPresent(record::getAppNum)
            .set(minRam).equalToWhenPresent(record::getMinRam)
            .set(description).equalToWhenPresent(record::getDescription)
            .set(createdTime).equalToWhenPresent(record::getCreatedTime)
            .where(id, isEqualTo(record::getId))
        );
    }
}